<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 浅拷贝
        // 1.拷贝数组
        var arr = [1, 2, 5, 3]
        var arr2 = arr
        arr2.push(10)
        console.log(arr2)
        // 2.拷贝对象
        var obj = {
            name: '胖鸡',
            age: 20
        }
        var obj2 = obj
        obj2.sex = '男'
        console.log(obj2)

        // 深拷贝
        // 1.拷贝数组
        var arr3 = []
        arr.map((val) => {
            arr3.push(val)
        })
        arr3.push(12)
        console.log(arr3)
        // 拷贝对象
        var obj2 = {
            name: '胖胖',
            age: 23,
            sex: '男'
        }
        var obj3 = {}
        for (var key in obj2) {
            obj3[key] = obj2[key]
        }
        obj3['num'] = 66
        console.log(obj3)


    </script>

</body>

</html>